<script setup lang="ts">
// import { Button as VanButton, Field as VanField } from 'vant'
import { request } from '@/utils/request'
import { useUserStore } from './stores'
import type { User } from './types/user'
const store = useUserStore()

// 测试响应拦截器
const login = async () => {
  // const res = await instance.post('/login/password', {
  //   mobile: '13230000085',
  //   password: 'abc12345'
  // })
  // console.log('login', res)
  // store.setUser(res.data)
  const res = await request<User>('/login/password', 'POST', {
    mobile: '13230000085',
    password: 'abc12345'
  })
  console.log('login', res.data)
  store.setUser(res.data)
}
// 测试请求拦截器 token在请求拦截器中处理
const getUser = async () => {
  // const res = await instance.get('/patient/myUser')
  // console.log('getUser', res)
  const res = await request('/patient/myUser')
  console.log('getUser', res)
}
</script>

<template>
  <div>用户信息：{{ store.user }}</div>
  <button @click="login">登录</button>
  <button @click="getUser">请求用户信息</button>
  <!-- <button
    @click="
      store.setUser({
        id: '1',
        mobile: '1',
        account: '1',
        avatar: '1',
        token: '1'
      })
    "
  >
    存储用户信息
  </button>
  <button @click="store.delUser()">删除用户信息</button> -->
</template>

<style scoped></style>
